package com.arron.ssm.utils;

/**
 * @Classname Generator
 * @Description TODO
 * @Date 2020/6/17 12:07
 * @Created by 刘
 */
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import sun.applet.Main;

import java.util.ArrayList;
import java.util.List;

public class Generator {

    public void generator() throws Exception{
//        new HashSet<>();
        List<String> warnings = new ArrayList<String>();
//已经创建了是否覆盖
        boolean overwrite = true;
//注意这里最好采用绝对路径，否则容易出现找不到文件
//        File configFile = new File("classpath:Mybatis-Generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(Main.class.getResourceAsStream("/Mybatis-Generator.xml"));
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                callback, warnings);
        myBatisGenerator.generate(null);

    }

    public static void main(String[] args) throws Exception {
        try {
            Generator generatorSqlmap = new Generator();
            generatorSqlmap.generator();
            System.out.println("mybatis 代码生成成功。。。");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
